package com.zhuang.principle.segregation;

/**
 * @Classname Sergregation
 * @Description 接口隔离原则
 * @Date 2021/3/15 13:02
 * @Created by dell
 */

public class Sergregation {
    public static void main(String[] args) {
        C c = new C();
        c.depend1(new A());
        c.depend2(new A());//C类通过接口去依赖A类
        c.depend3(new A());

        System.out.println("=======================");

        D d = new D();
        d.depend1(new B());
        d.depend4(new B());//D类通过接口去依赖B类
        d.depend5(new B());
    }
}
interface interface1{
    void operation1();
}

interface interface2{
    void operation2();
    void operation3();
}

interface interface3{
    void operation4();
    void operation5();
}

class A implements interface1,interface2{

    @Override
    public void operation1() {
        System.out.println("A 实现了operation1.....");
    }

    @Override
    public void operation2() {
        System.out.println("A 实现了operation2......");
    }

    @Override
    public void operation3() {
        System.out.println("A 实现了operation3......");
    }
}

class B implements interface1,interface3{
    @Override
    public void operation1() {
        System.out.println("B 实现了operation1.....");
    }

    @Override
    public void operation4() {
        System.out.println("B 实现了operation4.....");
    }

    @Override
    public void operation5() {
        System.out.println("B 实现了operation5.....");
    }
}

//C类通过接口interface1，interface2依赖使用A类 只会使用到1,2,3方法
class C{
    public void depend1(interface1 i){
        i.operation1();
    }

    public void depend2(interface2 i){
        i.operation2();
    }

    public void depend3(interface2 i){
        i.operation3();
    }
}

//D类通过接口interface1，interface3 依赖使用B类，用到1,4,5方法
class D{
    public void depend1(interface1 i){
        i.operation1();
    }

    public void depend4(interface3 i){
        i.operation4();
    }

    public void depend5(interface3 i){
        i.operation5();
    }
}